package com.ruoyi.controller.masterdate;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.jpjs.param.ParamService;
import com.ruoyi.service.jpjs.person.PersonService;
import com.ruoyi.service.masterdate.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/post")
public class PostController extends BaseController {

    private String prefix = "masterdate/post";

    @Autowired
    private PostService postService;

    @GetMapping()
    public String person() {
        return prefix + "/Post";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findPostAll(@RequestParam Map<String, Object> map) {
        List<Map<String, Object>> list = postService.findPostAll(map);
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String addPost() {
        return prefix + "/add";
    }

    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addPost(@RequestParam Map<String, Object> map) {
        return toAjax(postService.addPost(map));
    }

    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editPost(@RequestParam Map<String, Object> map) {
        return toAjax(postService.editPost(map));
    }

    @GetMapping("/edit/{id}")
    public String editPost(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("post", postService.findPost(id));
        return prefix + "/edit";
    }

}
